import logging

from google.appengine.ext import webapp 
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler 
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import taskqueue


class LogSenderHandler(InboundMailHandler):
    def receive(self, email): 
          
        logging.info("Incoming email from %s, subject %s" % (email.sender, email.subject)) 
        # check subject for URL
        
        if email.subject != "":
            taskParams = {}
            taskParams["url"] = email.subject 
            taskParams["email"] = email.sender 
            taskqueue.add(queue_name = "url2pdf",
                              url='/queue/url2pdf',
                              method='GET',
                              params = taskParams
                              )
        
application = webapp.WSGIApplication([LogSenderHandler.mapping()], debug=True)

def main():
    run_wsgi_app(application)
 
if __name__ == '__main__':
    main()